import 'package:daoyi_admin_ui_getx/app/modules/explore/views/explore_view.dart';
import 'package:daoyi_admin_ui_getx/app/modules/home/views/home_view.dart';
import 'package:daoyi_admin_ui_getx/app/modules/menus/views/menus_view.dart';
import 'package:daoyi_admin_ui_getx/app/modules/tabs/models/navigation_bar_Item_model.dart';
import 'package:daoyi_admin_ui_getx/app/modules/user_center/views/user_center_view.dart';
import 'package:daoyi_admin_ui_getx/generated/locales.g.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class TabsController extends GetxController {
  final currentIndex = 0.obs; //步骤3新增：新建一个变量，用于监听哪一个被选中
  final bottomNavigationBar = <NavigationBarItemModel>[
    NavigationBarItemModel(
      item: BottomNavigationBarItem(
        icon: const Icon(Icons.home),
        label: LocaleKeys.tabs_home.tr,
      ),
      page: const HomeView(),
    ),
    NavigationBarItemModel(
      item: BottomNavigationBarItem(
        icon: const Icon(Icons.category),
        label: LocaleKeys.tabs_menus.tr,
      ),
      page: const MenusView(),
    ),
    NavigationBarItemModel(
      item: BottomNavigationBarItem(
        icon: const Icon(Icons.explore),
        label: LocaleKeys.tabs_explore.tr,
      ),
      page: const ExploreView(),
    ),
    NavigationBarItemModel(
      item: BottomNavigationBarItem(
        icon: const Icon(Icons.school),
        label: LocaleKeys.tabs_user_center.tr,
      ),
      page: const UserCenterView(),
    ),
  ];

  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  /// 步骤3新增： 更新被选中的值
  void setCurrentIndex(index) {
    //将index赋值给currentIndex，并刷新数据
    currentIndex.value = index;
    update();
  }
}
